
 //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "DPCnsMtl.h"
#include "RLCnsMtl.h"
#include "DModule.h"
#include "DMMatl.h"

//---------------------------------------------------------------------------
#pragma package( smart_init )
#pragma link "DialPad"
#pragma link "PHDS"
#pragma link "PHEdit"
#pragma link "PHLabel"
#pragma link "PHGridEd"
#pragma link "PHCombo"
#pragma resource "*.dfm"
TDPCnsMtl1 * DPCnsMtl1;

//---------------------------------------------------------------------------
__fastcall TDPCnsMtl1::TDPCnsMtl1( TComponent*  Owner ) : TDiPad( Owner )
{
  PHDS1->Tabela = DM->TBGeral;
  DSMtl->Tabela = DM->TBMtlUso;
}

//---------------------------------------------------------------------------
void __fastcall TDPCnsMtl1::BitBtn3Click( TObject*  Sender )
{
  TPedeRel1*  PR;
  TRLCnsMtl1*  RLCnsMtl1 = new TRLCnsMtl1( NULL );
  try
   {
    PR = new TPedeRel1( NULL );
    PR->Report = RLCnsMtl1->PHReport1;
    PR->ShowModal();
   }

  __finally
   {
    Close();
    delete RLCnsMtl1;
    delete PR;
   }
}

//---------------------------------------------------------------------------
void __fastcall TDPCnsMtl1::DSMtlAfterOpen( TObject*  Sender )
{
  Mtl = ( struct MTLUSO* ) DSMtl->Buffer;
}

//---------------------------------------------------------------------------
void __fastcall TDPCnsMtl1::BitBtn1Click( TObject*  Sender )
{
  if( !DPA->DPCnsMtlDataInicial )
   {
    throw Exception( "Informe 'Data Inicial'." );
   }

  if( !DPA->DPCnsMtlDataFinal )
   {
    throw Exception( "Informe 'Data Final'." );
   }

  if( DPA->DPCnsMtlDataInicial > DPA->DPCnsMtlDataFinal )
   {
    throw Exception( "'Data Inicial' deve ser menor que 'Data Final'." );

   }

  PHGridEdit1->Visible = true;
  BitBtn3->Enabled = true;
  ComboBox1->Enabled = true;
}

//---------------------------------------------------------------------------
void __fastcall TDPCnsMtl1::Desabilita( void )
{
  PHGridEdit1->Visible = false;
  DSMtl->EliminaTabela();
  BitBtn3->Enabled = false;
  ComboBox1->Enabled = false;
}

//---------------------------------------------------------------------------
void __fastcall TDPCnsMtl1::PHEdit1Change( TObject*  Sender )
{
  Desabilita();
}

//---------------------------------------------------------------------------
void __fastcall TDPCnsMtl1::PHEdit2Change( TObject*  Sender )
{
  Desabilita();
}

//---------------------------------------------------------------------------

